package com.tao.power.Controller;


import com.tao.power.Dto.LoginDto;
import com.tao.power.Dto.Result;
import com.tao.power.Enums.ErrorEnums;
import com.tao.power.Service.LoginService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/")
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    public Result Login(@RequestBody LoginDto loginDto, HttpServletRequest request){
        return loginService.Login(loginDto.getUsername(),loginDto.getPassword(),request);
    }

    @GetMapping("/logout")
    public Result Logout(HttpServletRequest request){
        HttpSession session=request.getSession();
        session.removeAttribute("token");
        return Result.ok("", ErrorEnums.Success.getValue());
    }
}
